<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>登录页面</title>
    <meta charset="UTF-8">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8 ? MYOA_CHARSET : htmlspecialchars($HTML_PAGE_CHARSET))?>" />
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
    <link rel="stylesheet" href="/lib/layui/layui/css/layui.css?20190817.1">
    <link rel="stylesheet" href="/lib/layui/layui/css/common.css">
    <script type="text/javascript" src="/js/jquery/jquery-1.9.1.js"></script>
    <script src="/lib/layui/layui/layui.js"></script>
    <script src="/lib/layui/layui/js/common.js?v=20190726" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/layui/layui/js/baseCode/base.js?v=2019080918:09" type="text/javascript" charset="utf-8"></script>
    <script src="/js/base/base.js" type="text/javascript" charset="utf-8"></script>
    <script src="/js/login/login.js?20201017.1"></script>
    <script charset="utf-8" src="/js/login/jsencrypt.js?202001017.1"></script>

    <script src="/js/jquery/jquery-3.4.1.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="/js/jquery/jquery-migrate-3.1.0.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="/js/jquery/jquery.cookie.js"></script>

</head>
<style>
    html{
        background: #fff;
    }
    .layui-tab{
        margin: 0px;
    }
    .layui-tab-card{
        box-shadow:none;
        border-style:none;
    }
    .head{
        text-align: center;
        margin-top: 30px;
    }
    .head img{
        width: 150px;
    }
    .mian{
        padding-bottom: 30px;
        box-sizing: border-box;
        margin-top: 100px;
    }
    .verif{
        width: 65%;
        display: inline-block;
        margin-right: 5px;
    }
    input{
        height: 40px;
    }
    .login,.login2,.loginoa{
        background-color: #13a78d;
        width: 50%;
        font-size: 16px;
        border-radius: 20px;
    }
    .verification{
        margin-top: 30px;
        display: none;
    }
    .mobilNo{
        width: 97%;
    }
    .layui-tab-card>.layui-tab-title .layui-this{
        background-color: #3399FF;
        color: #fff;
    }
    #btn{
        width: 29%;
        border: 1px solid #ccc;
        color: #666;
    }
</style>
<body>
<div class="layui-tab layui-tab-card" lay-filter="reportTabs">
    <ul class="layui-tab-title">
        <li class="layui-this">OA账号登录</li>
        <li>手机号登录</li>
    </ul>
    <div class="layui-tab-content" style="height: 70%;">
        <div class="layui-tab-item layui-show">
            <div class="mian">
                <%--logo--%>
                <div class="head">
                    <img src="/img/bureau.jpg" alt="">
                </div>
                <%--手机验证--%>
                <div style="padding: 10px;box-sizing: border-box">
                    <div style="margin-top: 50px">
                        <input type="text" name="user"  autocomplete="off" id="user" placeholder="请输入账号" class="layui-input">
                    </div>
                    <div style="margin-top: 30px;">
                        <input type="password" name="password" id="password" autocomplete="off" placeholder="请输入密码" class="layui-input">
                    </div>
                    <div style="text-align: center;margin-top:40px">
                        <button type="button" class="layui-btn layui-btn-normal loginoa">登录</button>
                    </div>
                </div>
            </div>
        </div>
        <%--手机号验证--%>
        <div class="layui-tab-item">
            <div class="mian">
                <%--logo--%>
                <div class="head">
                    <img src="/img/bureau.jpg" alt="">
                </div>
                <%--手机验证--%>
                <div style="padding: 10px;box-sizing: border-box">
                    <div style="margin-top: 50px">
                        <input type="text" name="mobilNo" autocomplete="off" placeholder="请输入手机号" class="layui-input mobilNo">
                    </div>
                    <div class="verification">
                        <input type="text" name="codeTime" autocomplete="off" placeholder="请输入验证码" class="layui-input verif">
                        <%--<input type="button" id="button1" value="获取验证码" onclick="settime()" style=";width: 30%;padding: 0;" />--%>

                        <input type="button" id="btn" value="获取验证码" onclick="sendemail()" /> <%--<button type="button" class="layui-btn  layui-btn-primary yzm" style="margin-top: -4px;background-color: #f2f2f2;width: 30%;padding: 0;">发送验证码</button>--%>
                    </div>
                    <div style="text-align: center;margin-top:40px">
                        <button type="button" class="layui-btn layui-btn-normal login">登录</button>
                        <button type="button" class="layui-btn layui-btn-normal login2" style="display: none">登录</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

</body>
</html>
<script>
    layui.use('element', function(){
        var $ = layui.jquery
            ,element = layui.element; //Tab的切换功能，切换事件监听等，需要依赖element模块

        //oa账号登录
        $('.loginoa').click(function(){
            var byName = $('#user').val();
            if (byName.length == 0) {
                layer.msg("请输入用户名！",{icon:2});
                return false;
            }
            var result = encryptPadding();
            var encryptor = new JSEncrypt();
            encryptor.setPublicKey(result);
            var pwd = encryptor.encrypt($('#password').val());
            var data = {
                userAgent: 'pcc',
                loginId: '1001',
                username: encryptor.encrypt($('#user').val()),
                password: pwd,
            };
            $.ajax({
                type: 'post',
                url: '/login',
                dataType: 'json',
                data: data,
                success: function (res) {
                    if (res.flag == true) {
                        window.location.href="/ContractNoView/ewxIndex"
                        var loginCokie = res.object;
                        loginCokie.language = $('#language').val().split('=')[1] || 'zh_CN';
                        loginCokie.company = $('#departs').val();
                        $.setCookie(loginCokie);
                        //同步请求
                        $.ajaxSettings.async = false;
                        var bol = 0 ;
                        $.get('/sysTasks/selectAll', function (datas) {
                            var datas = datas.obj;
                            for (var i = 0; i < datas.length; i++) {
                                if (datas[i].paraName == 'SEC_INIT_PASS_SHOW' && datas[i].paraValue == 1 && $('#password').val() == "") {
                                    bol = 1;
                                }
                            }
                        }, 'json')
                        if(bol != 0){
                            window.location.href = '/controlpanel/modifyInfo?1'
                        } else if (url == 'en_US') {
                            window.location.href = "main?lang=en_US";
                        } else if (url == 'zh_tw') {
                            window.location.href = "main?lang=zh_tw";
                        } else {
                            window.location.href = "main";
                        }
                    } else {
                        // 验证码刷新
                        $("#imgCode").attr('src', '/GetCodeImgServlet?' + Math.random())
                        if (res.code == 100040) {
                            layer.msg(res.msg);
                            reg.msg == 0;
                        }
                        if (res.code == 100035) {
                            past(res.code);
                            return;
                        }

                        if (res.code == 100060) {
                            window.location.href = "/defaultIndexErr?imageType=100060";
                        } else if (res.code == 100010) {
                            layer.msg("用户名或密码错误（错误代码：100010）",{icon:2});
                        } else if (res.code == 100040) {
                            layer.msg("登录失败，您的账号已被系统锁定，请1分钟后重试（错误代码：100040）",{icon:2});
                        } else if (res.code == 100050) {
                            layer.msg("登录失败，用户禁止登录（错误代码：100050）",{icon:2})
                        } else {
                            layer.msg("用户名或密码错误（错误代码：100010）",{icon:2});
                        }
                    }
                }
            })
        })
        // 手机账号登录
        $('.login').click(function(){
            var phone = $("input[name='mobilNo']").val();
            var testPhone = /^1(3|4|5|7|8|9)\d{9}$/;
            if (phone==""){
                layer.msg("请输入手机号码",{icon:2});
                return false;
            }else{
                if(!testPhone.test(phone)){
                    layer.msg("手机号输入格式有误，请重新输入！",{icon:2});
                    return false;
                }else{
                    $.ajax({
                        url:'/ContractNo/phoneVerification',
                        dataType:'json',
                        type:'get',
                        data:{
                            phone:phone
                        },
                        success:function(res){
                            if(res.msg == "内部OA用户通过" || res.msg=="非内部OA用户通过"){
                                window.location.href="/ContractNoView/ewxIndex"
                            }else{
                                $('.verification').show()
                                $('.login2').show()
                                $('.login').hide()

                                $('.login2').click(function(){
                                    var codeTime = $(".verif").val();
                                    if (codeTime==""){
                                        layer.msg("请输入验证码",{icon:2});
                                    }else{
                                        $.ajax({
                                            url: '/ContractNo/phoneVerification',
                                            dataType: 'json',
                                            type: 'get',
                                            data: {
                                                phone: phone,
                                                VerificationCode:$(".verif").val()
                                            },
                                            success:function(res){
                                                if(res.msg == "非内部OA用户通过"){
                                                    window.location.href="/ContractNoView/ewxIndex"
                                                }else{
                                                    layer.msg("验证失败，请从新验证！",{icon:2});
                                                }
                                            }
                                        })
                                    }
                                })
                            }
                        }
                    })
                }
            }
        })
    });
    var countdown=300;
    function sendemail(){
        var obj = $("#btn");
        $.ajax({
            url:'/ContractNo/smsNoCode',
            dataType: 'json',
            type: 'get',
            data: {
                Mobile: $('.mobilNo').val()
            },
            success:function(res){
                if(res.msg == 'ok'){
                    layer.msg("发送成功！",{icon:1});
                }else{
                    layer.msg("发送失败，请重新发送！",{icon:2});
                }
            }
        })
        settime(obj);

    }
    function settime(obj) { //发送验证码倒计时
        if (countdown == 0) {
            obj.attr('disabled',false);
            obj.val("获取验证码");
            countdown = 300;
            return;
        } else {
            obj.attr('disabled',true);
            obj.val("重新发送(" + countdown + ")");
            countdown--;
        }
        setTimeout(function() {
                settime(obj) }
            ,1000)
    }
</script>

